Worksheet 3, Math 151

DERIVATIVES

Introduction

Goals: In this worksheet you will learn two different Mathematica procedures for computing derivatives symbolically.

Examples

The first Mathematica command, D, is used to differentiate mathematical expressions such as (x^n) or sin(x).

D[x^n,x]
D[Sin[x],x]

The second way to deal with derivatives in Mathematica is via the Derivative function which usually is used with the well-known prime(') notation. In this case, f' denotes the derivative of the function f.

f[x_]:=x^n; f'[x]
f[x_]:=Sin[x]; f'[x]

Higher-order derivatives are given, respectively, by

D[x^n, {x,2}]

f[x_]:=Sin[x]; f''[x]

Example 1:

Recall that the volume of a right circular cone of radius r and height h is given by V=((π (r^2)h)/3).

Graphics3D[Cone[],Boxed->False]

We may enter this formula in Mathematica as:

v=Pi*r^2*h/3

In order to determine the instantaneous rate of change of the volume with respect to the radius of the base of the cone, we must compute the derivative (dv/dr). Since v above is given as a mathematical expression representing the volume of the cone in terms of the radius r we can enter the following command to accomplish this:

D[v,r]

Alternatively, we could define the volume as a function of the radius, and then use the prime to obtain the derivative (note that we first need to clear the variable v if we want to use the same letter again as the name of a function - try what happens if you don't use Clear):

Clear[v]
v[r_]:=Pi*r^2*h/3
v'[r]

Example 2:

Using integral calculus, it can be shown that the area, A( c ), bounded between the graph of y=x  cos x , the x-axis, and the vertical line x = c, where  0 <  c  < (π/2), is given by A( c )=c sin c+cos c-1. This situation is illustrated in the graph below.

The instantaneous rate of change in area with respect to c, is the function:  a(c)=A' (c).
To compute this function in Mathematica, it is most convenient to use the prime notation:

funcA[c_]:=c*Sin[c]+Cos[c]-1

a[c_]:= funcA'[c]
a[c]

You may also obtain the derivative (as a mathematical expression only) if you use the derivative operator, D.

aD=D[funcA[c],c]

Therefore, we see that the instantaneous rate of change in the bounded area with respect to c is simply  c cos c. Moreover, the second derivative, b =A'' , may also be computed using either the prime notation or the operator D as:

b[c_]:=funcA''[c]
b[c]
 bD=D[funcA[c],{c,2}]

Equivalently, b = a'. Therefore, we must have:

b[c_]:=a'[c]
b[c]
bD=D[aD,c]

We may plot a graph of A and its first two derivatives, a and b.

Plot[{funcA[c],a[c],b[c]},{c,0,Pi/2},PlotRange -> {-1,1},PlotStyle -> {{Red,Thick},{Blue,Thick},{Brown,Thick}}]

Example 3:

Both the prime notation and the differential operator D may also be applied when differentiating piecewise defined functions.
Consider the following function M, with the piecewise definition given in Mathematica by:

funcM[x_]:=Piecewise[{{x+2,x≥-2 && x≤-1},
{(x^2),x>-1 && x ≤2},{8-2x, x>2 && x ≤ 4}}]
funcM[x]

Now we differentiate M in the usual way, first using the prime:

m[x_]:= funcM'[x]
m[x]

Next, we plot a graph of M and its derivative m on the same coordinate plane.

Plot[{funcM[x],m[x]},{x,-2,4},PlotStyle -> {{Blue,Thick},{Red,Thick}}]

Alternatively, we use the D operator to differentiate the expression M(x):

m=D[funcM[x],x]

Finally, we again plot the graph of M with its derivative on the same coordinate plane.

Plot[{funcM[x],m},{x,-2,4},PlotStyle -> {{Blue,Thick},{Red,Thick}}]

Exercises

Exercise 1

In the figure below, the graph of the function y=f ( x ) is shown.

Write a piecewise formula in Mathematica for the function f, for -3≤x≤+3.

Plot a Mathematica graph of y=f ( x ) using your definition.

Use Mathematica to find the derivative of f.

Plot a Mathematica graph of  y=f ' ( x ) and verify that it agrees with the figure displayed above.

Construct a continuous function  F  for -3≤x≤+3 such that F (-3)= 1 and F'(x)=f(x)  for all -3≤x≤+3.

Plot the graph of the function y=F(x) using Mathematica.

Use Mathematica to check that F'(x)=f(x) for all -3≤x≤+3 .

Exercise 2

The trigonometric "polynomial" F(t)=0.78540-0.63662cos(2t)-0.07074cos(6t)-0.02546cos(10t)-0.01299cos(14t)

gives a good approximation to the sawtooth function s=G(t) shown below, over the interval [-π, π].

How well does the derivative of F approximate the derivative of G at the points where ((dG)/(dt)) is defined? To find out, carry out the following steps.

Graph F and G on the same coordinate plane over [-π, π].

Graph g=((dG)/(dt)) (where defined) over [-π, π].

Find f=((dF)/(dt)).

Graph f and g on the same coordinate plane. Where does the approximation of ((dG)/(dt))by ((dF)/(dt))seem to be best/least good?

Exercise 3

Let g be the greatest integer function, i.e., g(x)=greatest integer≤x. A graph of this function is shown below:

In Mathematica, g is called the Floor function.

(a) Define g in Mathematica by executing the command:

g[x_]:=Floor[x]

(b) Plot the graph of y=g(x) over the interval -3.5<x<3.5 to verify that it has been properly defined.

(c) Sketch a graph of the function h(x)=(x^2)g(x) in Mathematica.

(d) Indicate the x-coordinate of each point at which h is not differentiable whenever -3.5<x<3.5.

(e) Write a piecewise formula for h(x) in Mathematica on the interval -3.5<x<3.5.

(f) Use your piecewise formula for h from part (e) and prime notation or the derivative operator, D, to define the function h' in Mathematica for -3.5<x<3.5. Then sketch its graph.

Exercise 4

(a) Define the function f(x)=sin(π x) in Mathematica and plot its graph over the interval -3.5<x<3.5.

(b) Graph the function k(x)=f(x)g(x) where g is the Floor function described in Exercise 1. Note that this function k is continuous everywhere.

(c) Indicate all numbers x at which k is not differentiable. Explain your answer by discussing one-sided derivatives. You do not need to perform Mathematica computations here.

(d) Define a polynomial function p such that p(x)g(x) is continuous on the interval -3.5<x<3.5.

(e) Graph the function y=p(x)g(x) in Mathematica to demonstrate the continuity of this product function.